package backend.db;

import java.util.Collection;
import java.util.LinkedList;

public class Tables {
  public static final Collection<Table> tables = new LinkedList<Table>();
  static {
    // users:
    tables.add(new Table("users", new Column("username", "VARCHAR(32)", true), new Column("password",
        "VARCHAR(32)"), new Column("role", "VARCHAR(13)"), new Column("name", "VARCHAR(32)"), new Column(
        "phone", "VARCHAR(12)"), new Column("address", "VARCHAR(256)")));
    // role is 13 because 13 = max{ |administrator|, |student| }
    // phone is 12 for 10 digits + 2 hyphens (e.g. 050-123-4567)
    // courses:
    tables.add(new Table("courses", new Column("courseName", "VARCHAR(64)", true), new Column("courseId",
        "VARCHAR(6)", false, true), new Column("lecturerInCharge", "VARCHAR(32)"), new Column("moedA",
        "VARCHAR(10)"), new Column("moedB", "VARCHAR(10)"), new Column("description", "TEXT"), new Column(
        "creditPoints", "VARCHAR(3)"), new Column("capacity", "SMALLINT"), new Column("groupNum", "TINYINT"),
        new Column("owner", "VARCHAR(32)")));
    // course sessions:
    tables.add(new Table("sessions", new String[] { "courseId", "day", "startHour" }, new Column("courseId",
        "VARCHAR(6)"), new Column("day", "TINYINT"), new Column("startHour", "TINYINT"), new Column(
        "duration", "TINYINT"), new Column("teacherName", "VARCHAR(32)"), new Column("classLocation",
        "VARCHAR(128)"), new Column("isLecture", "BOOLEAN")));
    // registrations:
    tables.add(new Table("registrations", new String[] { "username", "courseName" }, new Column("username",
        "VARCHAR(32)"), new Column("courseName", "VARCHAR(64)"), new Column("groupNum", "TINYINT")));
    // capacities table
    tables.add(new Table("capacities", new Column("courseName", "VARCHAR(64)", true), new Column("space",
        "SMALLINT")));
  }
  
  static Table getTable(final String tableName) {
    for (final Table t : tables)
      if (t.name.equals(tableName))
        return t;
    return null;
  }
}
